<template>
  <!-- 货物总览查看历史修改 -->
  <el-dialog title="修改" :visible.sync="openHistoryDetailEdit" width="800px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
    <el-form ref="formParams" :model="formParams" :rules="rules" label-width="120px" :inline="true">
      <el-row>
        <el-col :span="12">
          <el-form-item label="条码" prop="sptm">
            <el-input
            v-model="formParams.sptm"
            :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="纱支" prop="wpggA" :rules="rules.wpggA">
                <el-select
                    v-model="formParams.wpggA"
                    placeholder="请选择纱支"
                    clearable
                    filterable
                    :loading="warehouseDetailsDropDown1Loading"
                >
                    <el-option
                        v-for="item in warehouseDetailsList.a"
                        :key="item.id"
                        :label="item.name"
                        :value="item.name"
                    />
                </el-select>
            </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="物品规格" prop="spzs">
            <el-input
            v-model="formParams.spzs"
            placeholder="请输入物品规格"
            clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工艺" prop="wpggB">
            <el-select
                v-model="formParams.wpggB"
                placeholder="请选择工艺"
                clearable
                filterable
                :loading="warehouseDetailsDropDown1Loading"
              >
                <el-option
                    v-for="item in warehouseDetailsList.b"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                />
            </el-select>
        </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="品牌" prop="spcd">
            <el-input
            v-model="formParams.spcd"
            placeholder="请输入品牌"
            clearable
            />
        </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工序" prop="wpggC">
             <el-select
                v-model="formParams.wpggC"
                placeholder="请选择工序"
                clearable
                filterable
                :loading="warehouseDetailsDropDown1Loading"
              >
                <el-option
                    v-for="item in warehouseDetailsList.c"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                />
            </el-select>
        </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="柜号" prop="spgh">
            <el-input
            v-model="formParams.spgh"
            placeholder="请输入柜号"
            clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用途" prop="wpggD">
            <el-select
                v-model="formParams.wpggD"
                placeholder="请选择用途"
                clearable
                filterable
                :loading="warehouseDetailsDropDown1Loading"
              >
                <el-option
                    v-for="item in warehouseDetailsList.d"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="批号" prop="spbh">
            <el-input
            v-model="formParams.spbh"
             placeholder="请输入批号"
            clearable
            />
        </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产地" prop="wpggE">
            <el-select
                v-model="formParams.wpggE"
                placeholder="请选择产地"
                clearable
                filterable
                :loading="warehouseDetailsDropDown1Loading"
              >
                <el-option
                    v-for="item in warehouseDetailsList.e"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
           <el-form-item label="物品备注" prop="spbz">
            <el-input
              v-model="formParams.spbz"
              placeholder="请输入物品备注"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="漂染性" prop="wpggF">
             <el-select
                v-model="formParams.wpggF"
                placeholder="请选择漂染性"
                clearable
                filterable
                :loading="warehouseDetailsDropDown1Loading"
              >
                <el-option
                    v-for="item in warehouseDetailsList.f"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="生产日期" prop="wpggG">
              <el-input
                v-model="formParams.wpggG"
                placeholder="请输入生产日期"
                clearable
              />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="颜色" prop="wpggH">
            <el-input
            v-model="formParams.wpggH"
            placeholder="请输入颜色"
            clearable
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleEdit('formParams')" v-hasPermi="['zhcloud:sjzl:modify']">修 改</el-button>
      </div>
  </el-dialog>
</template>

<script>
import { warehouseInDetailsDropDown1 } from "@/api/storage/commonGoods/warehouseIn"
import { historyDetailModify } from "@/api/storage/dataOverview/goodsOverview";


export default {
  name: "GoodsOverviewHistoryDetailEdit",
  data() {
    return {
      //纱织加载
      warehouseDetailsDropDown1Loading: true,
       // 表单校验
      rules: {},
      //弹窗状态
      openHistoryDetailEdit: false,
      //表单数据
      formParams:{},
      submitParams: {
        addr: "",
        aip: "",
        browser: "",
        spbh: "",
        spbhid: "",
        spbz: "",
        spcd: "",
        spgh: "",
        spmc: "",
        sppgdj: "",
        spzs: "",
        wpggA: "",
        wpggB: "",
        wpggC: "",
        wpggD: "",
        wpggE: "",
        wpggF: "",
        wpggG: "",
        wpggH: ""
      },
      warehouseSelectPositonList:[],
      warehouseDetailsList:[]
    };
  },
  methods: {
     /**选择纱织 */
    warehouseDetails() {
      this.warehouseDetailsDropDown1Loading = true
      warehouseInDetailsDropDown1({}).then(response => {
        this.warehouseDetailsList = response.data;
        this.warehouseDetailsDropDown1Loading = false
      });
    },
    /**修改 */
    handleHistoryDetailModify() {
      this.$modal.loading("数据正在修改中，请稍等...")
      historyDetailModify(this.submitParams).then(response => {
        this.$modal.closeLoading()
        this.$modal.msgSuccess('修改成功！')
        this.close()
        this.$emit('refresh', true)
      }).catch(()=> {
        this.$modal.closeLoading()
      })
    },

    //修改详情
    handleEdit(formName) {
      this.$refs[formName].validate((valid, data) => {
        if(valid) {
          this.$modal.confirm("是否修改？").then(()=> {
            const submitParams = this.submitParams
            const formParams = this.formParams
            for(let i in submitParams) {
              submitParams[i] = formParams[i]
            }
            this.handleHistoryDetailModify()
          }).catch(() => {})
        } else {
          for(let i in data) {
            const item = data[i]
            for(let j in item) {
              const message = item[j].message
              return this.$modal.msgError(message)
            }
          }
          return false
        }
      })
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭窗口 */
    close() {
      this.changeHistoryDetailEdit()
      this.reset()
    },
    /**改变窗口状态 */
    changeHistoryDetailEdit() {
      this.openHistoryDetailEdit = !this.openHistoryDetailEdit;
    },

    /**打开弹窗 */
    open(data) {
      this.changeHistoryDetailEdit()
      this.formParams = data
      this.warehouseDetails()
    },
  }
};
</script>
